/**
 * Created by GYL on 2018/7/25
 */
import React, { Component } from 'react';
import { Input, Select, Row, Col, Tabs, Card, InputNumber, Popover, Tag, Checkbox, Collapse, Table, Button } from 'antd';
import Container from '../../components/common/Container';
import MyTable from '../../components/common/MyTable';
import PublicService from '../../services/PublicService';
import request from '../../utils/request';
import style from './WordEdit.less';
import moment from 'moment';
import TableB from '../examine/sub/TableB';
const { TextArea } = Input;
const Panel = Collapse.Panel;
const Option = Select.Option;
const TabPane = Tabs.TabPane;
class WordDetails extends Component {

    constructor(props) {
        super(props)
        this.columns = [
            {
                title: '序号',
                dataIndex: 'num',
                width: '5%',
                align: "center",
                key: "1"
            },
            {
                title: '外勤任务',
                dataIndex: 'takeTime',
                width: '15%',
                align: "center",
                key: "2",

            },
            {
                title: '任务类型',
                dataIndex: 'standName',
                width: '15%',
                key: "3",
                align: "center",
                render: (text, record) => {
                    return <Select size="small" style={{ width: "100%", border: 0 }} defaultValue="安全检查" style={{ width: 120 }} onChange={this.onSelect.bind(this, record)}>
                        <Option value="安全检查">安全检查</Option>
                        <Option value="安全考核">安全考核</Option>
                    </Select>

                }

            },
            {
                title: '预计完成时间',
                dataIndex: 'number116',
                width: '10%',
                key: "4",
                align: "center",

            },
            {
                title: '操作',
                width: '10%',
                dataIndex: 'number145',
                align: "center",
                key: "5",
                render: (text, record) => {
                    return <Tag color="#108ee9">删除</Tag>

                }
            }


        ];

    }


    state = {
        loading: false,
        selectedRowKeys: [],
        selectedRows: [],
        dataSource: [],
        pageIndex: 1,
        pageSize: 10,
        idList: [],

        patrolPersonnelName: "",
        baseUserName: "",
        takeTime: "",

        taskName: "",
        taskType: "",
        willFinishTime: "",
        finishTime: "",

        signInTime: "",
        signInPlace: "",
        signInRemark: ""
    }

    componentDidMount() {
        console.log(PublicService.getCookie('WordDetailsId'))
        request({
            url: `/zhrq-web/patrol/patroltask/getPatrolTaskDto?id=${PublicService.getCookie('WordDetailsId')}`,
            method: 'GET',
        }).then(data => {
            console.log(data)
            if (data.rc === 0) {
                this.setState({
                    patrolPersonnelName: data.ret.patrolPersonnelName,
                    baseUserName: data.ret.baseUserName,
                    takeTime: moment(data.ret.takeTime).format("YYYY-MM-DD HH:mm:ss"),
                    finishType: data.ret.finishType === '检查记录表' ? true : false,
                    taskName: data.ret.taskName,
                    taskType: data.ret.taskType,
                    willFinishTime: moment(data.ret.willFinishTime).format("YYYY-MM-DD HH:mm:ss"),
                    finishTime: data.ret.finishTime,
                    signInType: data.ret.signInType,
                    signInTime: data.ret.signInTime,
                    signInPlace: data.ret.signInPlace,
                    signInRemark: data.ret.signInRemark,
                })
                //判断是否有表
                if (data.ret.finishType === '检查记录表') {
                    if (data.ret.commercialUseOfBottledGasDto) {

                        data.ret.commercialUseOfBottledGasDto.commercialUseOfBottledGasInformationDtoList.forEach((item, index) => {
                            item.paramName = item.assessId
                            item.initialValue = item.score
                            item.disabled = true
                        })
                        data.ret.commercialUseOfBottledGasDto.commercialUseOfBottledGasVetoItemDtoList.forEach((item, index) => {
                            item.paramName = item.itemVetoId
                            item.initialValue = item.veto
                            item.disabled = true
                        })
                        if (data.ret.commercialUseOfBottledGasDto.score === 0) {
                            data.ret.commercialUseOfBottledGasDto.score = "0"
                        }
                        this.setState({
                            totalArr: [
                                {
                                    name: "总分",
                                    paramName: "score",
                                    key: "1",
                                    initialValue: data.ret.commercialUseOfBottledGasDto.score,
                                    disabled: true
                                }
                            ],
                            headerArr: [
                                {
                                    name: "餐饮场所名称",
                                    paramName: "cateringName",
                                    key: "1",
                                    initialValue: data.ret.commercialUseOfBottledGasDto.cateringName,
                                    disabled: true
                                },
                                {
                                    name: "地址",
                                    paramName: "site",
                                    key: "2",
                                    initialValue: data.ret.commercialUseOfBottledGasDto.site,
                                    disabled: true
                                },
                                {
                                    name: "供气企业",
                                    paramName: "enterprise",
                                    key: "3",
                                    initialValue: data.ret.commercialUseOfBottledGasDto.enterprise,
                                    disabled: true
                                }

                            ],
                            bottomArr: [
                                {
                                    type: 'input',
                                    name: "检查考核人",
                                    paramName: "assessor",
                                    key: "1",
                                    initialValue: data.ret.commercialUseOfBottledGasDto.assessor,
                                    disabled: true
                                },
                                {
                                    type: "datePicker",
                                    name: "检查考核时间",
                                    paramName: "takeTime",
                                    key: "2",
                                    initialValue: moment(data.ret.commercialUseOfBottledGasDto.takeTime),
                                    disabled: true
                                }
                            ],
                            moddleArr: data.ret.commercialUseOfBottledGasDto.commercialUseOfBottledGasInformationDtoList,
                            footerArr: data.ret.commercialUseOfBottledGasDto.commercialUseOfBottledGasVetoItemDtoList,
                            customerName:"瓶装气商业用气场所安全检查考核评分表"

                        })

                    }

                    if(data.ret.bottledgasSupplystationScoreDto) {
                      
                            data.ret.bottledgasSupplystationScoreDto.bottledgasSupplystationScoreInformationDtoList.forEach((item, index) => {
                                item.paramName = item.assessId
                                item.initialValue = item.score
                                item.disabled = true
                            })
                            data.ret.bottledgasSupplystationScoreDto.bottledgasSupplystationScoreVetoItemDtoList.forEach((item, index) => {
                                item.paramName = item.itemVetoId
                                item.initialValue = item.veto
                                item.disabled = true
                            })
                            if (data.ret.bottledgasSupplystationScoreDto.score === 0) {
                                data.ret.bottledgasSupplystationScoreDto.score = "0"
                            }
        
                            this.setState({
                                totalArr: [
                                    {
                                        name: "总分",
                                        paramName: "score",
                                        key: "1",
                                        initialValue: data.ret.bottledgasSupplystationScoreDto.score,
                                        disabled: true
                                    }
                                ],
                                headerArr: [
                                    {
                                        name: "被检供应站名称",
                                        paramName: "supplystation",
                                        key: "1",
                                        initialValue: data.ret.bottledgasSupplystationScoreDto.supplystation,
                                        disabled: true
                                    },
                                    {
                                        name: "被检查人",
                                        paramName: "beInspector",
                                        key: "2",
                                        initialValue: data.ret.bottledgasSupplystationScoreDto.beInspector,
                                        disabled: true
                                    },
        
        
                                ],
                                bottomArr: [
                                    {
                                        type: 'input',
                                        name: "检查考核人",
                                        paramName: "assessor",
                                        key: "1",
                                        initialValue: data.ret.bottledgasSupplystationScoreDto.assessor,
                                        disabled: true
                                    },
                                    {
                                        type: "datePicker",
                                        name: "检查考核时间",
                                        paramName: "takeTime",
                                        key: "2",
                                        initialValue: moment(data.ret.bottledgasSupplystationScoreDto.takeTime),
                                        disabled: true
                                    }
                                ],
                                moddleArr: data.ret.bottledgasSupplystationScoreDto.bottledgasSupplystationScoreInformationDtoList,
                                footerArr: data.ret.bottledgasSupplystationScoreDto.bottledgasSupplystationScoreVetoItemDtoList,
                                customerName:"瓶装气供应站(点)安全检查考核评分表"
                            })
                       
                    }




                }
            }
        })




    }

    //下拉选择
    onSelect = (v, record) => {
        console.log(v, record)
    }

    onA = () => {
        this.props.history.goBack()
    }

    onGroupMo = (checkedValues) => {
        this.setState({
            GroupArrMo: checkedValues
        })
    }

    //保存按钮 
    save = () => {
        console.log(this.state.dataSource)
    }

    render() {
        const { loading, selectedRowKeys, dataSource, pageIndex, pageSize, name, number116, number145, number500 } = this.state
        const windowWidth = document.body.clientWidth;
        const columns = this.columns
        const height = document.body.clientHeight;
        let containerHeight = '92vh';
        if (windowWidth > 1367) {
            containerHeight = '92vh';
        }

        return (
            <div>
                <Container
                    style={{ height: containerHeight, position: "relative", marginTop: "1vh", padding: "0px 10px" }}
                    header={true}
                >
                    <Row>
                        <Col span={12}><a onClick={this.onA}>外勤任务管理</a> >> 查看任务</Col>
                        <Col span={12}><a onClick={this.onA} style={{ float: "right" }}>返回</a></Col>
                    </Row>

                    <Row>
                        <Col span={6}>巡查人员 : {this.state.patrolPersonnelName}</Col>
                        <Col span={6}>分配人员 : {this.state.baseUserName}</Col>
                        <Col span={6}>分配时间 : {this.state.takeTime}</Col>
                    </Row>

                    <Row>
                        <Col span={6}>巡查任务 : {this.state.taskName}</Col>
                        <Col span={6}>任务类型 : {this.state.taskType == 1 ? "供应站点巡查" : "商业用户巡查"}</Col>
                        <Col span={6}>预计完成时间 : {this.state.willFinishTime}</Col>
                        <Col span={6}>实际完成时间 : {this.state.finishTime ? this.state.finishTime : ""}</Col>
                    </Row>




                    <Tabs defaultActiveKey="1" >
                        <TabPane tab="签到信息" key="1">
                            <Row>
                                <Col span={6}>签到类型 : {this.state.signInType == 1 ? "站点签到" : ""}</Col>

                                <Col span={6}>签到时间 : {this.state.signInTime ? this.state.signInTime : ""}</Col>
                                <Col span={6}>签到地点 : {this.state.signInPlace}</Col>
                            </Row>
                            <br />
                            <Row>
                                <Col span={6}>签到备注 : </Col>
                            </Row>
                            <TextArea rows={4} value={this.state.signInRemark} />
                        </TabPane>
                        <TabPane tab="检查记录表" key="2">
                            {
                                this.state.finishType &&
                                <div style={{ height: "65vh", overflow: "auto",padding:10 }}>
                                    <TableB
                                        customerName={this.state.customerName}
                                        headerArr={this.state.headerArr}
                                        moddleArr={this.state.moddleArr}
                                        footerArr={this.state.footerArr}
                                        bottomArr={this.state.bottomArr}
                                        totalArr={this.state.totalArr}
                                    />
                                </div>

                            }



                        </TabPane>

                    </Tabs>



                </Container>
            </div>
        )
    }
}
export default (WordDetails);
